package Thread;

public class SyncDemo4 {
    public static void main(String[] args) {
        Aoo aoo = new Aoo();
        Boo boo = new Boo();
        Thread t1 = new Thread(){
            @Override
            public void run() {
                aoo.methodA();
            }
        };

        Thread t2 = new Thread(){
            @Override
            public void run() {
                boo.methodB();
            }
        };

        t1.start();
        t2.start();
    }

}

class Aoo{
    public  void methodA(){
        synchronized ("123"){
            try {
                Thread t  = Thread.currentThread();
                System.out.println(t.getName()+":正在执行Aff");
                Thread.sleep(3000);
                System.out.println(t.getName()+":A方法执行结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}

class Boo {
    public  void methodB(){
        synchronized ("123"){
            try {
                Thread t  = Thread.currentThread();
                System.out.println(t.getName()+":正在执行Bff");
                Thread.sleep(3000);
                System.out.println(t.getName()+":B方法执行结束");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}